# bsb.py

import sys
import os
import optparse
import barco.error
import barco.sandbox

## main() ##
def main():
    sandbox = barco.sandbox.Sandbox()
    def set_config(option, opt, value, parser): sandbox.set_config(value)
    
    usage = list()
    usage.append('usage: bsb [options] <command> [args]')
    usage.append('')
    usage.append('Valid bsb commands are:')
    usage.append('')
    usage.append('  create    Creates a new sandbox')
    usage.append('  update    Updates an existing sandbox')    

    parser = optparse.OptionParser(usage='\n'.join(usage), version='0.1')
    parser.add_option('-c', '--config', 
                      type='string', 
                      action='callback', callback=set_config,
                      help='sandbox configuration file')
    (option, args) = parser.parse_args()

    # update is our default command
    if len(args) == 0: args = [ 'update' ]
    
    # make sure our commands are lowercase
    command = args[0].lower()
    
    try: 
        
        if command == 'create': return sandbox.create(args[1:])
        if command == 'update': return sandbox.update(args[1:])
    
    except barco.error.Error as e: parser.error(str(e))
    parser.error('invalid command specified: [%s]' % args[0])

# execute main() if we are being run as standalone script.
if __name__ == '__main__': sys.exit(main())










